package com.ttdevs.tvolley.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.toolbox.ImageLoader;
import com.ttdevs.tvolley.R;
import com.ttdevs.tvolley.app.VolleyInit;
import com.ttdevs.tvolley.bean.ImageInfo;

public class LeftListAdapter extends BaseAdapter {
	private Context context;
	private ArrayList<ImageInfo> infos;

	private ImageLoader mImageLoader;

	public LeftListAdapter(Context context, ArrayList<ImageInfo> infos) {
		this.context = context;
		this.infos = infos;

		mImageLoader = VolleyInit.getImageLoader();
	}

	@Override
	public int getCount() {
		return infos.size();
	}

	@Override
	public ImageInfo getItem(int position) {
		return infos.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		convertView = LayoutInflater.from(context).inflate(R.layout.list_item_image_left, null);
		
		TextView tvUrl = (TextView) convertView.findViewById(R.id.tvUrl);
		tvUrl.setText(getItem(position).getUrl());
		
		ImageView imageView = (ImageView) convertView.findViewById(R.id.ivItem);
		mImageLoader.get(getItem(position).getUrl(), ImageLoader.getImageListener(imageView, R.drawable.ic_launcher, R.drawable.ic_launcher));

		return convertView;
	}
}
